package hibdeveloperguide.dbaccess;

import org.hibernate.Session;
import org.hibernate.Transaction;

public class ConnectionTest {
	
	public static void main(String[] args) throws Exception {
		Session s = SessionManager.getSessionFactory().openSession();
//		Session s = SessionManager.getSessionFactory().getCurrentSession();
		Transaction tx = null;
		try {
			tx = s.beginTransaction();			

			Auto a = new Auto();
			a.setMarca("Ford");
			a.setModelo("Ka");
			
			s.saveOrUpdate(a);
			
			tx.commit();
		} catch(Exception e) {
			if(tx != null) {
				tx.rollback();
			}
			throw e;
		} finally {
			s.close();
		}		
	}
}